package cn.truistic.enmicromsg.base;

import android.accessibilityservice.AccessibilityService;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
import android.widget.Toast;

import cn.truistic.enmicromsg.app.EnApplication;
import cn.truistic.enmicromsg.wx.wx_friendscircle.FriendsCircleHeple;
import cn.truistic.enmicromsg.wx.wx_keysendmessage.KeySendMessageHeper;
import cn.truistic.enmicromsg.wx.wx_nearby.WeChatNearbyHeper;

/**
 * Created by admin on 2018/6/15.
 * name: ts
 * 用途: 微信自动化辅助
 */

public class WeChatAutomationService extends AccessibilityService {

    private EnApplication mApplication ;  //Application 上下文对象
    private WeChatNearbyHeper weChatNearbyHeper;  // 01  附近的人的模块
    private KeySendMessageHeper keySendMessageHeper;// 02 一键发送消息
    private FriendsCircleHeple friendsCircleHeple; // 03 自动点赞和评论朋友圈

    @Override
    public void onAccessibilityEvent(AccessibilityEvent event) {
        mApplication = (EnApplication) getApplication();
        int eventType = event.getEventType();
        if ( event.getSource() != null ) {
            /**
             * 01 . 附近的人
             */
            if (mApplication.isNearbyPeople() ){
                if (weChatNearbyHeper == null ){
                    weChatNearbyHeper = new  WeChatNearbyHeper(mApplication,this);
                }
                weChatNearbyHeper.isAutomationNearby(event,eventType);
            }
            /**
             * 02 . 一键发消息模块08
             */
            if (mApplication.isAKeySendMessage()) {
                if ( keySendMessageHeper == null ){
                    keySendMessageHeper = new KeySendMessageHeper(mApplication,this);
                }
                keySendMessageHeper.isAutomationNearby(event,eventType);
            }
            /**
             * 03 .自动点赞和评论朋友圈
             */
            if ( mApplication.isFriendCircle() ) {
                if ( friendsCircleHeple == null ) {
                    friendsCircleHeple = new FriendsCircleHeple(mApplication,this);
                }
                friendsCircleHeple.isAutomationNearby(event,eventType);
            }
        }
    }

    @Override
    public void onInterrupt() {
        Toast.makeText(this, "服务结束了，请手动打开服务-----", Toast.LENGTH_SHORT).show();
    }
}
